package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/1/8 10:03
 * @apiNote
 */

public class Test00949LargestTimeFromDigits {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4};
        String str = largestTimeFromDigits(arr);
        System.out.println(str);
    }

    public static String largestTimeFromDigits(int[] arr) {
        int ans = -1;
        for(int i = 0;i < 4;i++){
            for(int j = 0;j < 4;j++){
                if(j!=i){
                    for(int k = 0;k < 4;k++){
                        if(k != i && k!=j){
                            int l = 6-i-j-k;
                            int hours = 10 * arr[i] +arr[j];
                            int minutes = 10 * arr[k] + arr[l];
                            if(hours <24 && minutes <60){
                                ans = Math.max(ans,hours * 60 + minutes);
                            }
                        }
                    }
                }
            }
        }
        return ans >= 0 ? String.format("%02d:%02d",ans/60,ans%60):"";
    }
}
